let loginModule = (function () {

    let $username = $('.userName'),
        $userPass = $('.userPass'),
        $submit = $('.submit');
    // 点击按钮要进行的操作
    function handle() {
        $submit.click(async function () {
            // 表单校验
            let account = $username.val().trim(),
                password = $userPass.val().trim();
            if (account == "" || password == "") {
                alert('亲，用户名和密码不能为空哦(*￣︶￣)')
                return
            }
            // 给password加密
            password = md5(password)
            // 发送请求
            let result = await axios.post('/user/login', {
                account,
                password
            })
            if (parseInt(result.code) === 0) {
                alert('小主，已为您登录成功，即将跳转到首页~~')
                window.location.href = 'index.html'
                return
            }
            // 如果用户输入的用户名密码不匹配
            alert('小主，您输入的用户名密码不匹配，请重新输入o(╥﹏╥)o')
        })
    }
    return {
        init() {
            // 点击按钮触发handle
            handle()
        }
    }
})()
loginModule.init()